

const { Schema, model } = require('mongoose')


// Schema  声明表结构   对表的数据进行约束  (表字段的 类型校验)

const UserSchema = new Schema({
    id: String,
    username: String,
    phone: String,
    password: String,
    avatar: String,  // 头像
    nickname: String,
    email: String,
    age: Number,
    sex: Number,
    time: Date,
    role: Number,  // 用户权限 (学员 1  班主任 2 讲师 3 主管 4  校长 5  董事长 6 )
})




// model  链接表  操作表 对数据表进行 增删改查   (操作表里面的文档模型)
// 暴露了 
// 表名必须是复数 users = users  
// city =>  cities 
// citys 
// lists
// goods
// students

exports.UserModel = model('users', UserSchema)


// const umodel = model('users',{
//     id:String,
//     username:String,
//     phone:String,
//     password:String,
//     avatar:String,
//     nickname:String,
//     email:String,
//     age:Number,
//     sex:Number, 
// })



const GoodSchema = new Schema({
    "id": String,
    "zhu10id": String,
    "name": String,
    "price": Number,
    "discount": Number,
    "img": String,
    "type": Object
})


exports.GoodModel = model("goods", GoodSchema)


const CartSchema = new Schema({
    "goodId": String,  // 购买的商品ID
    "count": Number, // 购买数量
    "username": String,  // 购买人 
    "good": Object,  // 购买的商品具体数据 
})


exports.CartModel = model("carts", CartSchema)


const RoleSchema = new Schema({
    "id": Number,
    "value": Number,
    "label": String,
    "color": String,
})


exports.RoleModel = model("roles", RoleSchema)


// 公告表 
const AnnoSchema = new Schema({
    "id": Number,
    "type": Number,
    "title": String,
    "content": String,
    "author": Object,   // 提交人 
    time: Date,
    desc: String // 公告图片
})


exports.AnnoModel = model("annos", AnnoSchema)


// 学科表  
const XuekeSchema = new Schema({
    "id": Number,
    value: String,
    label: String,
    time: Date
})


exports.XuekeModel = model("xuekes", XuekeSchema)


// 班级表  
const ClassSchema = new Schema({
    "id": Number,
    xueke: String,
    year: String,
    num: String,
    time: Date,
    label: String,
    value: String,   // 'html5-22-14'
})


exports.ClassModel = model("classes", ClassSchema)




// 意见表  
const AdviseSchema = new Schema({
    "id": Number,
    "type": Array,
    "title": String,
    "content": String,
    "author": Object,   // 提交人 
    time: Date,
})


exports.AdviseModel = model("advises", AdviseSchema)




// 
// 评论表
const CommentSchema = new Schema({
    "id": Number,
    "type": Array,
    "title": String,
    "content": String,
    "author": Object,   // 提交人 
    time: Date,
})


exports.CommentModel = model("comments", CommentSchema)